detail<template>
  <div>
    <zeda-dialog
      v-model="visible"
      width="1200px"
      title="查看详情"
      :before-close="handleClose"
    >
      <Title name="基本信息" :line="true" slot="green">
        <desc-base-info
          :data="info"
          :colnum-info="baseInfo"
          align="right"
          :no-line-height="true"
          label-width="150px"
          class="base-info"
        >
          <template slot="status">
            <dict-tag
              :options="dict.type.energy_carbon_neutral_status"
              :value="info.status"
            />
          </template>
          <template slot="energyType">
            <dict-tag
              :options="dict.type.energy_type"
              :value="info.energyType"
            />
          </template>
        </desc-base-info>
      </Title>
      <Title
        v-for="(item, index) in info.plans"
        :key="index"
        :name="item.planName"
        :line="false"
        class="mt20"
      >
        <el-table :data="item.children" border max-height="300">
          <el-table-column label="" width="55" align="center">
            <template slot-scope="scope">
              <el-checkbox v-model="scope.row.checked" disabled></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column
            prop="energyName"
            label="名称"
            width="120"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="measureTotalFee"
            label="总价"
            min-width="80"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="measureNum"
            label="数量"
            min-width="80"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="measurePrice"
            label="单价"
            min-width="80"
            align="center"
          >
          </el-table-column>
        </el-table>
      </Title>

      <form-button
        slot="footer"
        :show-submit-button="false"
        @cancel="handleClose"
      >
      </form-button>
    </zeda-dialog>
  </div>
</template>
    <script>
import { detail } from "@/api/carbonNeutral/government";
import FormButton from "@/components/FormButton";
import { mul, formatDate, replaceDigit } from "@/utils/index";
export default {
  dicts: ["energy_type", "energy_carbon_neutral_status"],
  components: {
    FormButton,
  },
  props: {
    visible: { type: Boolean, default: false },
    id: { type: [String, Number], default: "" },
  },
  data() {
    return {
      info: {},
    };
  },
  filters: {
    dictFee(val) {
      const text = val ? mul(val, 100) + "%" : "";
      return text;
    },
    formatTime(val) {
      const text = val ? formatDate(val) : "";
      return text;
    },
  },
  computed: {
    baseInfo({ info }) {
      let arr = [];
      arr = [
        {
          label: "用能单位",
          prop: "deptName",
          colNum: 3,
        },
        {
          label: "统计年份",
          prop: "year",
          colNum: 3,
          unit: "年",
        },
        {
          label: "实际能耗",
          prop: "energyVal",
          colNum: 3,
          unit: "kwh",
        },
        { label: "能耗类型", prop: "energyType", colNum: 3 },
        {
          label: "实际费用",
          prop: "energyValFee",
          colNum: 3,
          unit: "元",
        },
        {
          label: "能耗预算",
          prop: "budgetFee",
          colNum: 3,
          unit: "元",
        },
        {
          label: "预算年中调整",
          prop: "adjustFee",
          colNum: 3,
          unit: "元",
        },

        {
          label: "预算年中盈利",
          prop: "surplusFee",
          colNum: 3,
          unit: "元",
        },
        {
          label: "确认状态",
          prop: "status",
          colNum: 3,
        },
        {
          label: "备注",
          prop: "remark",
          colNum: 3,
        },
      ];
      return arr;
    },
  },
  watch: {
    visible(value) {
      if (value && String(this.id).length > 0) {
        this.getInfo();
      }
    },
  },
  methods: {
    getInfo() {
      const that = this;
      detail(that.id)
        .then((res) => {
          if (res.code === 700) {
            that.$message.warning(res.msg);
            return false;
          }
          this.info = res.data;
          //   this.list = this.info.plans.map((item) => {
          //     item.children = item.children.filter((_) => _.checked === true);
          //     return item;
          //   });
        })
        .catch((err) => {
          this.info = {};
          // this.$message.error("系统错误,请联系管理员!300077");
        });
    },
    handleClose(status) {
      this.$emit("update:visible", false);
      this.$emit("close", status === true ? status : false);
    },
  },
};
</script>
